#ifndef _UTILS_H_
#define _UTILS_H_

#include"Common.h"

#include<type_traits>
#include<functional>

namespace Craft
{
	const GLfloat float_accuracy = 0.00001f;

	template <typename T>
	typename std::enable_if<std::is_arithmetic<T>::value, T>::type Max(T t1, T t2)
	{
		if (t1 > t2)
		{
			return t1;
		}
		else
		{
			return t2;
		}
	}


	template <typename T>
	typename std::enable_if<std::is_arithmetic<T>::value, T>::type Min(T t1, T t2)
	{
		if (t1 < t2)
		{
			return t1;
		}
		else
		{
			return t2;
		}
	}


	template <typename T>
	void change(T& t1, T& t2)
	{
		T t = t1;
		t1  = t2;
		t2  = t;
	}


	/*
		@brief 用于对glm库的vec3遍历
	*/
	template <typename Func>
	inline void for_range_glmVec3(const glm::vec3& begin, const glm::vec3& end, Func func)
	{
		glm::vec3 tmp;
		for (tmp.x = begin.x; tmp.x < end.x; tmp.x++)
			for (tmp.y = begin.y; tmp.y < end.y; tmp.y++)
				for (tmp.z = begin.z; tmp.z < end.z; tmp.z++)
					func(tmp);
	}


	/*
		@brief 用于对glm库的vec3大小判定
	*/
	inline bool less_glmVec3(const glm::vec3& v1, const glm::vec3& v2)
	{
		if (v1.x != v2.x)
			return v1.x < v2.x;
		if (v1.y != v2.y)
			return v1.y < v2.y;
		
		return v1.z < v2.z;
	}

	/*
	@brief 用于对glm库的vec3大小判定
	*/
	inline bool equal_glmVec3(const glm::vec3& v1, const glm::vec3& v2)
	{
		return (fabs(v1.x - v2.x) < float_accuracy &&
				fabs(v1.y - v2.y) < float_accuracy &&
				fabs(v1.z - v2.z) < float_accuracy);
	}

}

#endif